package com.bawei.hfgc.frgacty.viewModel;

import androidx.databinding.ObservableField;

import com.bawei.hfgc.frgacty.ConfigEntity;
import com.bawei.hfgc.frgacty.model.FragmModel;
import com.bawei.hfgc.frgacty.widget.BottomButton;
import com.bawei.mvvmcomm.mvvm.viewmodel.BaseViewModel;
import com.bawei.networkmoudle.Entity.BaseEntity;
import com.bawei.networkmoudle.uitls.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class FregmViewModel extends BaseViewModel<FragmModel> implements BottomButton.SelectListener{

    public ObservableField<List<ConfigEntity.Values>> bottomes;


    @Override
    protected void initData() {
        bottomes=new ObservableField<List<ConfigEntity.Values>>();

        Map<String,Object> map = new HashMap<>();
        map.put("imie",""+System.currentTimeMillis());
        m.requestConfig(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);

    }

    @Override
    protected FragmModel createModel() {
        return new FragmModel();
    }

    @Override
    protected void sucessFull(BaseEntity entity) {
        if (entity instanceof ConfigEntity){
            ConfigEntity configEntity = (ConfigEntity) entity;
            configEntity.data.get(0).selFlag = true;
            bottomes.set(configEntity.data);
            getUiChangeLiveData().getSelFragment().setValue(configEntity.data.get(0).arouterURL);
            LogUtils.show(configEntity.getMessage());
        }
    }

    @Override
    public void onSelect(int id) {
        List<ConfigEntity.Values> datas = new ArrayList(bottomes.get());
        for (int i = 0;i < datas.size();i++){
            if (id == i){
                getUiChangeLiveData().getSelFragment().setValue(datas.get(i).arouterURL);
                datas.get(i).selFlag=true;
                LogUtils.show("onSelect:true");
            }else
                datas.get(i).selFlag=false;
            LogUtils.show("onSelect:false");
        }
        bottomes.set(datas);
//        bottomes.notifyChange();
//        hideFragment();
//        showFragment(id);

    }




}
